
package modules.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import modules.common.GenUtils;
import modules.model.GenTable;
import modules.service.GeneratorService;

 

/**
 * 业务表Controller
 * @author Ruoli
 * @version 2017-08-31
 */
@Controller
@RequestMapping(value = "/gen")
public class GenController {

	@Autowired
	private GeneratorService genService;
	
	@RequestMapping(value = "step1")
	public String step1(GenTable genTable, Model model) {
		// 获取物理表列表
		List<GenTable> tableList = genService.findTableListFormDb(new GenTable());
		model.addAttribute("tableList", tableList);
		// 获取物理表字段
		return "step1";
	}
	
	@RequestMapping(value = "step2")
	public String step2(GenTable genTable, Model model) {
		// 获取物理表字段
		genTable = genService.getTableFormDb(genTable);
		model.addAttribute("model", genTable);
		model.addAttribute("config", GenUtils.getConfig());
		return "step2";
	}

	
	@RequestMapping(value = "build")
	public String build(GenTable genTable, Model model) {
		String result = genService.buildCode(genTable);
		model.addAttribute("message", "操作成功，生成结果如下：<br/>"+result);
		return "result";
		
	}
}
